const md5 = require('md5');
const User = require('../../db/userSchame');
module.exports = async(req, res) => {
    let usermsgObj = {
        username: req.body.username,
        password: md5(req.body.password),
        age: req.body.age,
        sex: req.body.sex,
        address: req.body.address,
    };
    //    添加到数据库中

    // {
    //     username: 'momokotest',
    //     password: '81dc9bdb52d04dc20036dbd8313ed055',
    //     age: 20,
    //     sex: '女',
    //     address: '郑州',
    //     _id: new ObjectId("61e8c7e9fcea9ac34bebb3b0"),
    //     createTime: 2022-01-20T02:24:41.404Z,
    //     __v: 0
    //   }
    // try:写正常的情况业务逻辑,catch会自动捕获系统异常
    try {
        await User.create(usermsgObj);
        res.redirect('/admin/userlist');
    } catch (error) {
        res.status(500).send('添加失败');
    }
};